package com.hmall.gateway.filters;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @author chanchaw
 * @create 2025-08-05 10:44
 */
@Component
public class TestParamsGatewayFilterFactory extends AbstractGatewayFilterFactory<TestParamsGatewayFilterFactory.Config> {
    @Data
    public static class Config {
        private String sid;
        private String name;
    }
    @Override
    public List<String> shortcutFieldOrder(){
        return List.of("sid","name");
    }

    public TestParamsGatewayFilterFactory(){
        super(Config.class);
    }

    @Override
    public GatewayFilter apply(Config config) {
        return new OrderedGatewayFilter(new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("接受到的参数是：" + config.toString());
                return chain.filter(exchange);
            }
        }, -2);
    }
}
